home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / KEYBOARD.SWG / 0026_Another Ctrl-Break Trap.pas < prev    next >
Pascal/Delphi Source File  |  1993-06-22  |  1KB  |  55 lines

  1. UNIT Break;
  2. {This unit traps the Ctrl-Break sequence}
  3.  
  4. INTERFACE
  5. USES
  6.   DOS;
  7. CONST
  8.   BrkTrapped : Boolean = FALSE;
  9. PROCEDURE TrapCtrlBrkOn;
  10. PROCEDURE TrapCtrlBrkOff;
  11.  
  12. IMPLEMENTATION
  13. CONST
  14.   CtrlBrkInterrupt     = $1B;
  15.   BrkTrapSet : Boolean = FALSE;
  16. VAR
  17.   OldBrkVector : Pointer;
  18. { The following procedure is the new Ctrl-Break
  19.   Interrupt handler. It traps the Ctrl-Break key
  20.   sequence and setsa flag for the currently
  21.   running program to check.  You should do any
  22.   special processing based on this flag's value}
  23. {$F+}
  24. PROCEDURE NewCtrlBrkVector; INTERRUPT;
  25. {$F-}
  26. BEGIN
  27.   INLINE($FA); {Clear interrupts instruction -CLI}
  28.   {Reset bit 7 low}
  29.   Mem[$0040:$0071] := Mem[$0040:$0071] AND $E;
  30.   BrkTrapped := TRUE;
  31.   INLINE($FB) {Set interrupts instruction - STI}
  32. END;
  33.  
  34. PROCEDURE TrapCtrlBrkOn;
  35. BEGIN
  36.   {Make sure no stacked calls are possible}
  37.   IF NOT BrkTrapSet THEN
  38.    BEGIN
  39.     BrkTrapSet := TRUE;
  40.     GetIntVec(CtrlBrkInterrupt, OldBrkVector);
  41.     SetIntVec(CtrlBrkInterrupt, @NewCtrlBrkVector)
  42.    END
  43. END;
  44.  
  45. PROCEDURE TrapCtrlBrkOff;
  46. BEGIN {Check if there is an old vector to restore}
  47.   IF BrkTrapSet THEN
  48.     BEGIN
  49.       BrkTrapSet := FALSE;
  50.       SetIntVec(CtrlBrkInterrupt, OldBrkVector)
  51.     END
  52. END;
  53.  
  54. END.
  55.